
import { App } from "vue";


// router store guard
import router from '@/shared/router';
import { createRouterGuard } from '@/shared/guard';
import store from '@/shared/store';

//use config
import { useConfig as platformUseConfig } from '@/platform/configs/use';
import { useConfig as businessUseConfig } from '@/business/configs/use';


// antd组件
import {
    Button, Form, Input, Card, Dropdown,
    InputNumber, Row, Col, Select, Modal,
    Menu, Table, Alert, Tag, Drawer, Progress,
    Descriptions, Divider, List, DatePicker,
    Tabs, Tree, Checkbox, Transfer, Tooltip,
    TreeSelect, Collapse, Upload
} from "ant-design-vue";


// 使用的配置
const useConfig = {
    // antd 组件
    antdComponents: [
        Button, Form, Input, Card, Dropdown,
        InputNumber, Row, Col, Select, Modal,
        Menu, Table, Alert, Tag, Drawer, Progress,
        Descriptions, Divider, List, DatePicker,
        Tabs, Tree, Checkbox, Transfer, Tooltip,
        TreeSelect, Collapse, Upload
    ],
    //第三方组件
    thirdPartyComponents: [
        ...platformUseConfig.thirdPartyComponents,
        ...businessUseConfig.thirdPartyComponents
    ],
    //自定义组件
    customComponents: [
        ...platformUseConfig.customComponents,
        ...businessUseConfig.customComponents
    ],
    //自定义指令
    customDirectives: [
        ...platformUseConfig.customDirectives,
        ...businessUseConfig.customDirectives
    ],
    // 路由守卫
    routerGuards: () => {
        createRouterGuard(router)
    }
}



/**
 * 使用ant 组件
 * @param app 
 */
function useAntdComponnet(app: App) {
    useConfig.antdComponents.forEach((componnet) => {
        app.use(componnet);
    })
}

/**
 * 使用第三方组件
 * @param app 
 */
function useThirdPartyComponents(app: App) {
    useConfig.thirdPartyComponents.forEach((componnet) => {
        app.use(componnet);
    })
}

/**
 *  使用自定义组件
 * @param app  应用根
 */
function useCustomComponent(app: App) {
    useConfig.customComponents.forEach((customComponent) => {
        app.component(customComponent.name, customComponent.component);
    });
}

/**
 *  使用自定义指令
 * @param app  应用根
 */
function useCustomDirectives(app: App) {
    useConfig.customDirectives.forEach((customDirective) => {
        app.directive(customDirective.name, customDirective.directive);
    });
}

/**
 * 使用路由
 * @param app 
 */
function useRouter(app: App) {
    app.use(router);
    useConfig.routerGuards();
}

/**
 * 使用store
 * @param app 
 */
function useStore(app: App) {
    app.use(store);
}

/**
 * 使用所有
 * @param app  应用根
 */
export function useAll(app: App) {
    useAntdComponnet(app);
    useThirdPartyComponents(app);
    useCustomComponent(app);
    useCustomDirectives(app);
    useRouter(app);
    useStore(app);
    return app;
}


